//
//  ViewController.m
//  picture
//
//  Created by 刘晓凯 on 2017/3/13.
//  Copyright © 2017年 刘晓凯. All rights reserved.
//

#import "ViewController.h"
#import "XKPictureCollectionView.h"
#import "UIImage+Extend.h"

@interface ViewController ()<XKPictureCollectionViewDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self testXKPictureCollectionView];

//    [self testCVPixelBufferRef];
}

/**
 仿 nice app 中照片详情的图片展示样式
 */
- (void)testXKPictureCollectionView {
    CGSize screenSize = [UIScreen mainScreen].bounds.size;
    CGRect newFrame = CGRectMake(0, 0, screenSize.width, 0);
    XKPictureCollectionView *picture1 = [[XKPictureCollectionView alloc] initWithFrame:CGRectZero Images:nil];
    picture1.pictureDelegate = self;
    picture1.frame = newFrame;
    picture1.imageArray = [NSMutableArray arrayWithObjects:@"08.jpg",@"08.jpg",@"08.jpg",@"08.jpg",@"08.jpg",@"08.jpg",@"08.jpg", nil];
    [self.view addSubview:picture1];
    [picture1 reloadPictureData];
    
}

/**
 UIImage 与 CVPixelBufferRef 的互转
 */
- (void)testCVPixelBufferRef {
    CGSize screenSize = [UIScreen mainScreen].bounds.size;
    UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 20, screenSize.width, 200)];
    [self.view addSubview:imageView1];
    imageView1.image = [UIImage imageNamed:@"08.jpg"];
    
    UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 240, screenSize.width, 200)];
    [self.view addSubview:imageView2];
    
    CGImageRef imageRef= [imageView1.image CGImage];
    CVPixelBufferRef bufferRef = [UIImage pixelBufferFromCGImage1:imageRef];
    imageView2.image = [UIImage imageFromPixelBuffer:bufferRef];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark -XKPictureCollectionViewDelegate

- (void)selectedObject:(id)object dataArray:(NSArray *)dataArray {
    NSLog(@"XKPictureCollectionViewDelegate--%@--%@",object,dataArray);
}

@end
